# encoding: utf-8
# @File  : test02.py
# @Author: wu shaofan
# @Date  :  2024/04/17
# @Desc :
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

from config import BASE_DIR





driver_path = BASE_DIR + r'/tools/126.0.6478.57/chromedriver.exe'
# 创建 ChromeOptions 对象
options = Options()

# 创建 Chrome WebDriver 服务
service = Service(driver_path)
# 创建 Chrome WebDriver 实例
driver = webdriver.Chrome(service=service, options=options)
driver.maximize_window()
# 打开百度网页
driver.get("https://hmshop-test.itheima.net/Home/user/login.html")
driver.find_element(By.ID, "username").send_keys("18325530001")
driver.find_element(By.ID, "password").send_keys("wsf123456")
driver.find_element(By.ID, "verify_code").send_keys("8888")
driver.find_element(By.CSS_SELECTOR, ".J-login-submit").click()

loc = By.LINK_TEXT, '地址管理'
WebDriverWait(driver, 10, 0.5).until(expected_conditions.element_to_be_clickable(loc)).click()

loc = By.CSS_SELECTOR, 'a[class="address"] span'
WebDriverWait(driver, 10, 0.5).until(expected_conditions.element_to_be_clickable(loc)).click()

address_name = By.NAME, 'consignee'
WebDriverWait(driver, timeout=10, poll_frequency=0.5).until(expected_conditions.presence_of_element_located(address_name), '元素未找到').send_keys('wsf')

address_phone = By.NAME, 'mobile'
WebDriverWait(driver, timeout=10, poll_frequency=0.5).until(expected_conditions.presence_of_element_located(address_phone), '元素未找到').send_keys('18325530001')

address_province = By.ID, 'province'
ele =WebDriverWait(driver, timeout=10, poll_frequency=0.5).until(expected_conditions.presence_of_element_located(address_province), '元素未找到')
select = Select(ele)
select.select_by_visible_text("安徽省")

address_city = By.ID, 'city'


ele =WebDriverWait(driver, timeout=10, poll_frequency=0.5).until(expected_conditions.presence_of_element_located(address_city), '元素未找到')
select = Select(ele)
time.sleep(1)
select.select_by_visible_text("铜陵市")


time.sleep(5)